﻿/*
 * MIT License
 *
 * Copyright (c) Microsoft Corporation.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 *
 * ------------------------------------------------------------------------------ 
 * <auto-generated> 
 * This code was generated by a tool at:
 * /utils/doclint/generateDotnetApi.js
 * 
 * Changes to this file may cause incorrect behavior and will be lost if 
 * the code is regenerated. 
 * </auto-generated> 
 * ------------------------------------------------------------------------------
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Runtime.Serialization;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.Playwright
{
	/// <summary>
	/// <para>
	/// The Worker class represents a <a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API">WebWorker</a>.
	/// <c>worker</c> event is emitted on the page object to signal a worker creation. <c>close</c>
	/// event is emitted on the worker object when the worker is gone.
	/// </para>
	/// <code>
	/// Page.Worker += (_, worker) =&gt;<br/>
	/// {<br/>
	///     Console.WriteLine($"Worker created: {worker.Url}");<br/>
	///     worker.Close += (_, _) =&gt; Console.WriteLine($"Worker closed {worker.Url}");<br/>
	/// };<br/>
	/// <br/>
	/// Console.WriteLine("Current Workers:");<br/>
	/// foreach(var pageWorker in Page.Workers)<br/>
	/// {<br/>
	///     Console.WriteLine($"\tWorker: {pageWorker.Url}");<br/>
	/// }
	/// </code>
	/// </summary>
	public partial interface IWorker
	{
		/// <summary>
		/// <para>
		/// Emitted when this dedicated <a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API">WebWorker</a>
		/// is terminated.
		/// </para>
		/// </summary>
		event EventHandler<IWorker> Close;
	
		/// <summary>
		/// <para>Returns the return value of <paramref name="expression"/>.</para>
		/// <para>
		/// If the function passed to the <see cref="IWorker.EvaluateAsync"/> returns a <see
		/// cref="Promise"/>, then <see cref="IWorker.EvaluateAsync"/> would wait for the promise
		/// to resolve and return its value.
		/// </para>
		/// <para>
		/// If the function passed to the <see cref="IWorker.EvaluateAsync"/> returns a non-<see
		/// cref="Serializable"/> value, then <see cref="IWorker.EvaluateAsync"/> returns <c>undefined</c>.
		/// Playwright also supports transferring some additional values that are not serializable
		/// by <c>JSON</c>: <c>-0</c>, <c>NaN</c>, <c>Infinity</c>, <c>-Infinity</c>.
		/// </para>
		/// </summary>
		/// <param name="expression">
		/// JavaScript expression to be evaluated in the browser context. If it looks like a
		/// function declaration, it is interpreted as a function. Otherwise, evaluated as an
		/// expression.
		/// </param>
		/// <param name="arg">Optional argument to pass to <paramref name="expression"/>.</param>
		Task<T> EvaluateAsync<T>(string expression, object arg = default);
	
		/// <summary>
		/// <para>Returns the return value of <paramref name="expression"/> as a <see cref="IJSHandle"/>.</para>
		/// <para>
		/// The only difference between <see cref="IWorker.EvaluateAsync"/> and <see cref="IWorker.EvaluateHandleAsync"/>
		/// is that <see cref="IWorker.EvaluateHandleAsync"/> returns <see cref="IJSHandle"/>.
		/// </para>
		/// <para>
		/// If the function passed to the <see cref="IWorker.EvaluateHandleAsync"/> returns
		/// a <see cref="Promise"/>, then <see cref="IWorker.EvaluateHandleAsync"/> would wait
		/// for the promise to resolve and return its value.
		/// </para>
		/// </summary>
		/// <param name="expression">
		/// JavaScript expression to be evaluated in the browser context. If it looks like a
		/// function declaration, it is interpreted as a function. Otherwise, evaluated as an
		/// expression.
		/// </param>
		/// <param name="arg">Optional argument to pass to <paramref name="expression"/>.</param>
		Task<IJSHandle> EvaluateHandleAsync(string expression, object arg = default);
	
		string Url { get; }
	
		/// <summary><para>Performs action and waits for the Worker to close.</para></summary>
		/// <param name="timeout">
		/// Maximum time to wait for in milliseconds. Defaults to <c>30000</c> (30 seconds).
		/// Pass <c>0</c> to disable timeout. The default value can be changed by using the
		/// <see cref="IBrowserContext.SetDefaultTimeout"/>.
		/// </param>
		Task<IWorker> WaitForCloseAsync(float? timeout = default);
	}
}